# _*_ coding: utf-8 _*_


"""
auth: bigger.wing
version: v1.0
function: cve-2019-0708漏洞检测
usage:
note: 借助于poc做检测, 3389_hosts为IP地址清单，0708detector.exe为poc
"""


import os
import subprocess
from multiprocessing.dummy import Pool as ThreadPool


current_abs_path = os.path.abspath(__file__)
current_abs_path_dir = os.path.dirname(current_abs_path)
poc = os.path.abspath(current_abs_path_dir) + '/0708detector.exe'
hosts_file = os.path.abspath(current_abs_path_dir) + '/3389_hosts'


def cve_2019_0708(ip, port='3389'):
    command = poc + ' -t ' + ip + ' -p ' + port
    result = subprocess.getoutput(command)

    # print(command, '\n', result)

    if 'WARNING: SERVER IS VULNERABLE' in result:
        result = '%s 存在CVE-2019-0708漏洞' % ip
    else:
        result = '%s 不存在CVE-2019-0708漏洞' % ip

    print(result)


if __name__ == '__main__':
    rdp_hosts = []
    with open(hosts_file, 'r') as f:
        data = f.readlines()
        for x in data:
            ip = x.strip()
            rdp_hosts.append(ip)

    pool = ThreadPool(20)
    pool.map(cve_2019_0708, rdp_hosts)
